#encoding=utf-8
from django.forms import ModelForm
from django import forms
from .models import Ship
from django.core.exceptions import NON_FIELD_ERRORS
from django.contrib.admin import widgets
import datetime


class AddShipForm(ModelForm) :
	"""添加船只的表单"""
	def send_email(self):
		pass
	class Meta:
		model  = Ship
		fields = ['ship_id', 'user_id', 'protocol_id', 'ship_owner_id', 'ship_type_id', 'manager_id', 'name', 'name_chinese', 'imo', 'mmsi', 'call_sign', 'flag', 'build_time']

class SearchHistoryForm(forms.Form):

	def get_year(param):
		year = datetime.datetime.now().year+2
		SEARCH_YEAR_CHOICE_BE = []
		SEARCH_YEAR_CHOICE_EN = []
		for i in range(2000, year):
			SEARCH_YEAR_CHOICE_BE.append(str(i))
			SEARCH_YEAR_CHOICE_EN.insert(0, str(i))
		if param == 'be':
			return tuple(SEARCH_YEAR_CHOICE_BE)
		else :
			return tuple(SEARCH_YEAR_CHOICE_EN)
	begintime = forms.DateTimeField(required=True,label='开始时间',widget=forms.SelectDateWidget(years=get_year('be')),)
	endtime = forms.DateTimeField(required=True,label='结束时间',widget=forms.SelectDateWidget(years=get_year('en')),
    initial=datetime.datetime.now(),)
